#include <bits/stdc++.h>
#define st first
#define nd second
#define ll long long
#define MP make_pair
using namespace std;
const int N=2e5+5;
int n,color[N];
ll a[N],mx;
ll sum(){
   ll ans=0,lx=-1,ly=-1;
   for(int i=0;i<n;i++){
        if(color[i]){
            if(a[i]==lx)ans+=lx;
            lx=a[i];
        }
        else{
            if(a[i]==ly)ans+=ly;
            ly=a[i];
        }
   }
   return ans;
}
void dfs(int i){
    if(i==n){
        mx=max(mx,sum());
        return ;
    }
    dfs(i+1);
    color[i]=1;
    dfs(i+1);
    color[i]=0;
}
void solve(int t){
    mx=0;
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    dfs(0);
    cout<<mx;
    if(t!=1)cout<<"\n";
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T=1;
    cin>>T;
    for(int i=T;i>=1;i--)solve(i);
    return 0;
}
